<?php
declare (strict_types = 1);

namespace app\auth\service;

use app\auth\model\DeptModel;

class DeptService  extends BaseService
{
    public function __construct(DeptModel $deptModel)
    {
        $this->deptModel = $deptModel;
    }

    public function list(array $where = [] , array $limit = [], array $sort= []){
        $limit = check_limit($limit);
        $sort = check_sort($sort);
        return $this->deptModel::with([DeptModel::WITH_ROLES])
            ->where($where)
            ->limit($limit['page'],$limit['pagesize'])
            ->order($sort[0],$sort[1])
            ->select();
    }

    public function count(array $where = []){
        return $this->deptModel->where($where)->count();
    }

    public function insertGetId(array $data = []){
        return $this->deptModel->insertGetId($data);
    }

    public function update(array $where = [],array $data = []){
        return $this->deptModel->where($where)->update($data);
    }

    public function delete(array $whereIn = []){
        return $this->deptModel->whereIn($whereIn[0],$whereIn[1])->delete();
    }
}
